package com.jinsi.mapper.ylt;

import com.jinsi.pojo.SyUserCouponUsed;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @ClassName CouponMapper
 * @Content 优惠券持久层
 * @Author 姚龙腾
 * @Date 2022/10/12 10:40
 */
@Mapper
public interface CouponMapper {


    /**
     * 查询有的优惠券(模糊查询所需的信息)
     * @param discountsName
     * @param discountsType
     * @param discountsQuantity
     * @return List<SyUserCouponUsed>
     */
    List<SyUserCouponUsed> getAll(
            String discountsName,
            String discountsType,
            Integer discountsQuantity);


    /**
     * 添加的优惠券
     * @param coupon
     * @return int
     */
    int addCoupon(SyUserCouponUsed coupon);


    /**
     * 修改上架还是下架
     * @param discountsId
     * @param discountsQuantity
     * @return int
     */
    int upCouponState(
            @Param("discountsId") int discountsId,
            @Param("discountsQuantity") int discountsQuantity);


    /**
     * 优惠券总数量减一
     * @param discountsId
     * @param discountsAmount
     * @return int
     */
    int upCouponNum(int discountsId, int discountsAmount);


    /**
     * 发放优惠券
     * @param userId
     * @param discountsId
     * @return int
     */
    @Insert("insert into sy_discounts_issuance(user_id,discounts_id) values(#{userId},#{discountsId})")
    int addUserCoupon(Integer userId,Integer discountsId);

}